home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / jovept1.arc / INC.C < prev    next >
Text File  |  1985-05-30  |  3KB  |  166 lines

  1. /* inc.c */
  2.  
  3. /* JOVE/MSDOS. K. Mitchum 1/85 */
  4. /* Modifications for personal use only. */
  5. /* original code J. Payne LSRHS 5/83 */
  6. /* Ken Mitchum */
  7. /* University of Pittsburgh */
  8. /* Decision Systems Laboratory */
  9.  
  10. /*
  11.    Jonathan Payne at Lincoln-Sudbury Regional High School 5/25/83
  12.   
  13.    Incremental search here...  */
  14.  
  15. #include "jove.h"
  16.  
  17. #define FOUND    1
  18. #define GOBACK    2
  19. #define CharCom(a, b) (IsFlagSet(globflags, CASEIND) ? (Upperc(a) == Upperc(b)) : (a == b))
  20.  
  21. extern char    searchbuf[];
  22.  
  23. static char IncBuf[100],
  24.         *incp = 0;
  25. static int FirstInc = 0;
  26. static jmp_buf incjmp;
  27.  
  28.  
  29. IncFSearch()
  30. {
  31.     IncSearch(1);
  32. }
  33.  
  34. IncRSearch()
  35. {
  36.     IncSearch(-1);
  37. }
  38.  
  39.  
  40.  
  41. IncSearch(direction)
  42. {
  43.     BUFLOC    bp;
  44.  
  45.     DOTsave(&bp);
  46.     switch (setjmp(incjmp)) {
  47.     case GOBACK:
  48.         SetDot(&bp);
  49.         break;
  50.  
  51.     case 0:
  52.         IncBuf[0] = 0;
  53.         incp = IncBuf;
  54.         FirstInc = 1;
  55.         SetMark();
  56.         isearch(direction, 0, 0);
  57.         break;
  58.  
  59.     case FOUND:
  60.     default:
  61.         break;
  62.     }
  63.     message(IncBuf);    /* Show the search string */
  64.     setsearch(IncBuf);    /* This is now the global string */
  65. }
  66.  
  67. isearch(direction, failing, ctls)
  68. {
  69.     char    c;
  70.     BUFLOC    bp,
  71.         *newdot;
  72.     int    nextfail = failing;    /* Kind of a temp variable */
  73.  
  74.     DOTsave(&bp);
  75.     for (;;) {
  76.         s_mess("%s%sI-search: %s", failing ? "Failing " : "",
  77.                 direction < 0 ? "reverse-" : "", IncBuf);
  78.         c = (*Gtchar)();
  79.         switch (c) {
  80.         case '\177':
  81.         case CTL(H):
  82.             if (!ctls)    /* If we didn't repeated the command */
  83.                 if (incp > IncBuf)
  84.                     *--incp = 0;
  85.             return;
  86.  
  87.         case CTL([):
  88. okayleave:
  89.             longjmp(incjmp, FOUND);
  90.  
  91.         case CTL(\\):
  92.             c = CTL(S);
  93.         case CTL(R):
  94.         case CTL(S):
  95.             if (FirstInc && incp) {    /* We have been here before */
  96.                 FirstInc = 0;
  97.                 strcpy(IncBuf, searchbuf);
  98.                 incp = IncBuf + strlen(IncBuf);
  99.                 failing = 0;
  100.             }
  101.             /* If we are not failing, OR we are failing BUT we
  102.                are changing direction, then allow another
  103.                search */
  104.  
  105.             if (!failing || ((direction == -1 && c == CTL(S)) ||
  106.                     (direction == 1 && c == CTL(R)))) {
  107.                 newdot = dosearch(IncBuf, c == CTL(R) ? -1 : 1, 0);
  108.                 if (newdot) {
  109.                     SetDot(newdot);
  110.                     nextfail = 0;
  111.                 } else
  112.                     nextfail = 1;
  113.                 SetMark();
  114.                 isearch(c == CTL(R) ? -1 : 1, nextfail, 1);
  115.                 nextfail = failing;
  116.             } else
  117.                 rbell();
  118.             break;
  119.  
  120.         case CTL(G):
  121.             longjmp(incjmp, GOBACK);
  122.             /* Easy way out! */
  123.  
  124.         case CTL(Q):
  125.         case CTL(^):
  126.             c = (*Gtchar)() | 0200;    /* Tricky! */
  127.         default:
  128.             if (c & 0200)
  129.                 c &= 0177;
  130.             else {    /* Check for legality */
  131.                 if (c < ' ' && c != '\t') {
  132.                     peekc = c;
  133.                     goto okayleave;
  134.                 }
  135.             }
  136.             FirstInc = 0;    /* Not first time anymore! */
  137.             *incp++ = c;    /* Always put in string */
  138.             *incp = 0;
  139.             if (!failing) {
  140.                 if (direction > 0 && CharCom(linebuf[curchar], c))
  141.                     ForChar();
  142.                 else if (direction < 0 && CharCom(linebuf[curchar + strlen(IncBuf) - 1], c))
  143.                     ;
  144.                 else if (!failing) {
  145.                     newdot = dosearch(IncBuf, direction, 0);
  146.                     if (newdot == 0)
  147.                         nextfail++;
  148.                     else
  149.                         SetDot(newdot);
  150.                 }
  151.             }
  152.             isearch(direction, nextfail, 0);
  153.             nextfail = failing;
  154.             /* Reset this to what it was, because if we
  155.              * are here again, then we must have deleted
  156.              * back.
  157.              */
  158.         }
  159.         SetDot(&bp);
  160.     }
  161. }
  162.  
  163.  
  164. /*---------------------------o.s. dependent--------------------------*/
  165. /* end */
  166.